//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "AlphaFormLinearHyperbolic.h"
using namespace Cephei::QL::Models::Marketmodels::Models;
#include <gen/QL/Models/Marketmodels/Models/AlphaForm.h>
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Models::Marketmodels::Models::CAlphaFormLinearHyperbolic::CAlphaFormLinearHyperbolic (Cephei::Core::IVector<Double>^ times, Microsoft::FSharp::Core::FSharpOption<Double>^ alpha) : CAlphaForm(CAlphaFormLinearHyperbolic::typeid)
{
    try
    {
#ifdef HANDLE
        _phAlphaFormLinearHyperbolic = NULL;
#endif
        times->Lock();
        INativeVector<Double>^ _NCItimes = times->getFeature (NativeFeature::Value);
        CDoubleVector^ _NCtimes = safe_cast<CDoubleVector^>(_NCItimes);
        std::vector<QuantLib::Time>& _times = static_cast<std::vector<QuantLib::Time>&> (_NCtimes->GetReference ());
        QuantLib::Real _alpha = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (alpha) ? (QuantLib::Real)ValueHelper::Convert (alpha->Value) : 0.0); //4
        _ppAlphaFormLinearHyperbolic = new boost::shared_ptr<QuantLib::AlphaFormLinearHyperbolic> (new QuantLib::AlphaFormLinearHyperbolic ( _times,  _alpha ));
        SetAlphaForm (boost::dynamic_pointer_cast<QuantLib::AlphaForm> (*_ppAlphaFormLinearHyperbolic));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (times != nullptr) times->Unlock();    //not optional
    }
}
Cephei::QL::Models::Marketmodels::Models::CAlphaFormLinearHyperbolic::CAlphaFormLinearHyperbolic (boost::shared_ptr<QuantLib::AlphaFormLinearHyperbolic>& childNative, Object^ owner) : CAlphaForm(CAlphaFormLinearHyperbolic::typeid)
{
#ifdef HANDLE
	_phAlphaFormLinearHyperbolic = NULL;
#endif
	_ppAlphaFormLinearHyperbolic = &childNative;
    _ppAlphaForm = new boost::shared_ptr<QuantLib::AlphaForm> (boost::dynamic_pointer_cast<QuantLib::AlphaForm> (*_ppAlphaFormLinearHyperbolic));
}
Cephei::QL::Models::Marketmodels::Models::CAlphaFormLinearHyperbolic::CAlphaFormLinearHyperbolic (QuantLib::AlphaFormLinearHyperbolic& childNative, Object^ owner) : CAlphaForm(CAlphaFormLinearHyperbolic::typeid)
{
#ifdef HANDLE
	_phAlphaFormLinearHyperbolic = NULL;
#endif
	_ppAlphaFormLinearHyperbolic = new boost::shared_ptr<QuantLib::AlphaFormLinearHyperbolic> (&childNative);
    _ppAlphaForm = new boost::shared_ptr<QuantLib::AlphaForm> (boost::dynamic_pointer_cast<QuantLib::AlphaForm> (*_ppAlphaFormLinearHyperbolic));
    _AlphaFormLinearHyperbolicOwner = owner;
    _AlphaFormOwner = owner;
}

Cephei::QL::Models::Marketmodels::Models::CAlphaFormLinearHyperbolic::CAlphaFormLinearHyperbolic (CAlphaFormLinearHyperbolic^ copy) : CAlphaForm(CAlphaFormLinearHyperbolic::typeid)
{
#ifdef HANDLE
	_phAlphaFormLinearHyperbolic = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppAlphaFormLinearHyperbolic = new boost::shared_ptr<QuantLib::AlphaFormLinearHyperbolic> (copy->GetShared());
        _ppAlphaForm = new boost::shared_ptr<QuantLib::AlphaForm> (boost::dynamic_pointer_cast<QuantLib::AlphaForm> (*_ppAlphaFormLinearHyperbolic));
    }
}
Cephei::QL::Models::Marketmodels::Models::CAlphaFormLinearHyperbolic::CAlphaFormLinearHyperbolic (PLATFORM::Type^ t) : CAlphaForm(CAlphaFormLinearHyperbolic::typeid)
{
#ifdef HANDLE
	_phAlphaFormLinearHyperbolic = NULL;
#endif
	if (!t->IsSubclassOf(CAlphaFormLinearHyperbolic::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Models::Marketmodels::Models::CAlphaFormLinearHyperbolic::CAlphaFormLinearHyperbolic (QuantLib::Handle<QuantLib::AlphaFormLinearHyperbolic>& childNative, Object^ owner)  : CAlphaForm(CAlphaFormLinearHyperbolic::typeid)
{
	_phAlphaFormLinearHyperbolic = &childNative;
	_ppAlphaFormLinearHyperbolic = &static_cast<boost::shared_ptr<QuantLib::AlphaFormLinearHyperbolic>>(childNative.currentLink());
    _ppAlphaForm = new boost::shared_ptr<QuantLib::AlphaForm> (boost::dynamic_pointer_cast<QuantLib::AlphaForm> (*_ppAlphaFormLinearHyperbolic));
    _AlphaFormLinearHyperbolicOwner = owner;
}
Cephei::QL::Models::Marketmodels::Models::CAlphaFormLinearHyperbolic::CAlphaFormLinearHyperbolic (QuantLib::Handle<QuantLib::AlphaFormLinearHyperbolic> childNative)  : CAlphaForm(CAlphaFormLinearHyperbolic::typeid)
{
	_phAlphaFormLinearHyperbolic = &childNative;
	_ppAlphaFormLinearHyperbolic = &static_cast<boost::shared_ptr<QuantLib::AlphaFormLinearHyperbolic>>(childNative.currentLink());
    _ppAlphaForm = new boost::shared_ptr<QuantLib::AlphaForm> (boost::dynamic_pointer_cast<QuantLib::AlphaForm> (*_ppAlphaFormLinearHyperbolic));
}
#endif
#ifdef STRUCT
Cephei::QL::Models::Marketmodels::Models::CAlphaFormLinearHyperbolic::CAlphaFormLinearHyperbolic (QuantLib::AlphaFormLinearHyperbolic childNative)  : CAlphaForm(CAlphaFormLinearHyperbolic::typeid)
{
#ifdef HANDLE
	_phAlphaFormLinearHyperbolic = NULL;
#endif
	_ppAlphaFormLinearHyperbolic = new boost::shared_ptr<QuantLib::AlphaFormLinearHyperbolic> (new QuantLib::AlphaFormLinearHyperbolic (childNative));
    _ppAlphaForm = new boost::shared_ptr<QuantLib::AlphaForm> (boost::dynamic_pointer_cast<QuantLib::AlphaForm> (*_ppAlphaFormLinearHyperbolic));
}
#endif

Cephei::QL::Models::Marketmodels::Models::CAlphaFormLinearHyperbolic::~CAlphaFormLinearHyperbolic ()
{
    if (_ppAlphaFormLinearHyperbolic != NULL)
    {
	    delete _ppAlphaFormLinearHyperbolic;
        _ppAlphaFormLinearHyperbolic = NULL;
    }
}
Cephei::QL::Models::Marketmodels::Models::CAlphaFormLinearHyperbolic::!CAlphaFormLinearHyperbolic ()
{
    if (_ppAlphaFormLinearHyperbolic != NULL)
    {
	    delete _ppAlphaFormLinearHyperbolic;
    }
}
QuantLib::AlphaFormLinearHyperbolic& Cephei::QL::Models::Marketmodels::Models::CAlphaFormLinearHyperbolic::GetReference ()
{
    if (_ppAlphaFormLinearHyperbolic == NULL) throw REFNEW NativeNullException ();
	return **_ppAlphaFormLinearHyperbolic;
}
boost::shared_ptr<QuantLib::AlphaFormLinearHyperbolic>& Cephei::QL::Models::Marketmodels::Models::CAlphaFormLinearHyperbolic::GetShared ()
{
    if (_ppAlphaFormLinearHyperbolic == NULL) throw REFNEW NativeNullException ();
	return *_ppAlphaFormLinearHyperbolic;
}
QuantLib::AlphaFormLinearHyperbolic* Cephei::QL::Models::Marketmodels::Models::CAlphaFormLinearHyperbolic::GetPointer ()
{
    if (_ppAlphaFormLinearHyperbolic == NULL) throw REFNEW NativeNullException ();
	return &**_ppAlphaFormLinearHyperbolic;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::AlphaFormLinearHyperbolic>& Cephei::QL::Models::Marketmodels::Models::CAlphaFormLinearHyperbolic::GetHandle ()
{
	if (_phAlphaFormLinearHyperbolic == NULL)
	{
		_phAlphaFormLinearHyperbolic = new Handle<QuantLib::AlphaFormLinearHyperbolic> (*_ppAlphaFormLinearHyperbolic);
	}
	return *_phAlphaFormLinearHyperbolic;
}
#endif
bool Cephei::QL::Models::Marketmodels::Models::CAlphaFormLinearHyperbolic::HasNative () 
{
	return (_ppAlphaFormLinearHyperbolic != NULL);
}

Cephei::QL::Models::Marketmodels::Models::IAlphaFormLinearHyperbolic^ Cephei::QL::Models::Marketmodels::Models::CAlphaFormLinearHyperbolic::SetAlpha (Double alpha_)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::Real _alpha_ = (QuantLib::Real)ValueHelper::Convert (alpha_); //a
    	(*_ppAlphaFormLinearHyperbolic)->setAlpha ( _alpha_ );
    	return this;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Models::Marketmodels::Models::IAlphaFormLinearHyperbolic^ Cephei::QL::Models::Marketmodels::Models::CAlphaFormLinearHyperbolic_Factory::Create (Cephei::Core::IVector<Double>^ times, Microsoft::FSharp::Core::FSharpOption<Double>^ alpha)
{
    return REFNEW CAlphaFormLinearHyperbolic ( times,  alpha);
}
